<?php

function direct($url) {
	$chuyen = header("Location: $url");
	$chuyen .= exit();
	return $chuyen;


}
	class database{
		protected $_conn;
		protected $_results;
		public function __construct(){
			@$this->_conn = mysql_connect(config::HOST_NAME,config::HOST_USER,config::HOST_PASS) or die("can't connect sever");
			mysql_select_db(config::DB_NAME,$this->_conn) or die("not select database");
			mysql_query("SET NAMES utf8");
		}
		public function query($sql){
			if($this->_conn){
				$this->_results = mysql_query($sql);
			}
		}
		public function num_rows(){
			if($this->_results){
				$row = mysql_num_rows($this->_results);
			}else{
				$row = 0;
			}
			return $row;
		}
		public function select($sql) {
			$query = mysql_query($sql);
			while ($post = mysql_fetch_array($query)){
				$data[] = $post;
					
					
			}
			return $data;
		}
		public function fetch(){
			if($this->_results){
				$row = mysql_fetch_assoc($this->_results);
			}else{
				$row = 0;
			}
			return $row;
		}
		public function fetchAll(){
			$data = array();
			if($this->_results){
				while($row = $this->fetch()){
					$data[] = $row;
				}
				return $data;
			}
		}
		
			public function get_num_rows($sql){
		
				$row = mysql_num_rows(mysql_query($sql));
			
			
			
			return $row;
		}
		public function get_message_noview($id_user) {
	
			$data  = $this->get_num_rows("SELECT * FROM message WHERE user_to = '{$id_user}' AND view = 0");
			return $data;
				
		}
		public function select_one($sql) {
			$query = mysql_query($sql);
		  	$data= mysql_fetch_array($query);
						
		 	return $data;
		
		}
		public function insert ($sql) {
			$query = mysql_query($sql);
			$check = false;
			if($query) $check=true;
		
		
			return $check;
		}
		public function select_function_config($function) {
			$query = $this->select_one("SELECT * FROM config WHERE function = '{$function}' ");
			$check = false;
			if($query) $check=true;
		
		
			return $query['value'];
		}
		public function get_box($idproduct) {
			$query = $this->select("SELECT * FROM box_product WHERE productID = '{$idproduct}' ");
			$check = false;
			if($query) $check=true;
			
			
			return $query;
		}
		
		
	}